/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * File Name          : freertos.c
  * Description        : Code for freertos applications
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2025 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "global.h"
#include "task_init.h"
#include "task_acquire.h"
#include "task_key.h"
#include "task_show.h"
#include "task_store.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */

/* USER CODE END Variables */
/* Definitions for TASK_INIT */
osThreadId_t TASK_INITHandle;
const osThreadAttr_t TASK_INIT_attributes = {
  .name = "TASK_INIT",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityRealtime,
};
/* Definitions for TASK_KEY */
osThreadId_t TASK_KEYHandle;
const osThreadAttr_t TASK_KEY_attributes = {
  .name = "TASK_KEY",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityHigh,
};
/* Definitions for TASK_ACQUIRE */
osThreadId_t TASK_ACQUIREHandle;
const osThreadAttr_t TASK_ACQUIRE_attributes = {
  .name = "TASK_ACQUIRE",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityAboveNormal,
};
/* Definitions for TASK_STORE */
osThreadId_t TASK_STOREHandle;
const osThreadAttr_t TASK_STORE_attributes = {
  .name = "TASK_STORE",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityBelowNormal,
};
/* Definitions for TASK_SHOW */
osThreadId_t TASK_SHOWHandle;
const osThreadAttr_t TASK_SHOW_attributes = {
  .name = "TASK_SHOW",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for SYS_EVENT */
osEventFlagsId_t SYS_EVENTHandle;
const osEventFlagsAttr_t SYS_EVENT_attributes = {
  .name = "SYS_EVENT"
};

/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */

/* USER CODE END FunctionPrototypes */

void task_init(void *argument);
void task_key(void *argument);
void task_acquire(void *argument);
void task_store(void *argument);
void task_show(void *argument);

void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */

/**
  * @brief  FreeRTOS initialization
  * @param  None
  * @retval None
  */
void MX_FREERTOS_Init(void) {
  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* USER CODE BEGIN RTOS_MUTEX */
  /* add mutexes, ... */
  /* USER CODE END RTOS_MUTEX */

  /* USER CODE BEGIN RTOS_SEMAPHORES */
  /* add semaphores, ... */
  /* USER CODE END RTOS_SEMAPHORES */

  /* USER CODE BEGIN RTOS_TIMERS */
  /* start timers, add new ones, ... */
  /* USER CODE END RTOS_TIMERS */

  /* USER CODE BEGIN RTOS_QUEUES */
  /* add queues, ... */
  /* USER CODE END RTOS_QUEUES */

  /* Create the thread(s) */
  /* creation of TASK_INIT */
  TASK_INITHandle = osThreadNew(task_init, NULL, &TASK_INIT_attributes);

  /* creation of TASK_KEY */
  TASK_KEYHandle = osThreadNew(task_key, NULL, &TASK_KEY_attributes);

  /* creation of TASK_ACQUIRE */
  TASK_ACQUIREHandle = osThreadNew(task_acquire, NULL, &TASK_ACQUIRE_attributes);

  /* creation of TASK_STORE */
  TASK_STOREHandle = osThreadNew(task_store, NULL, &TASK_STORE_attributes);

  /* creation of TASK_SHOW */
  TASK_SHOWHandle = osThreadNew(task_show, NULL, &TASK_SHOW_attributes);

  /* USER CODE BEGIN RTOS_THREADS */
   /* add threads, ... */
  /* USER CODE END RTOS_THREADS */

  /* Create the event(s) */
  /* creation of SYS_EVENT */
  SYS_EVENTHandle = osEventFlagsNew(&SYS_EVENT_attributes);

  /* USER CODE BEGIN RTOS_EVENTS */
   osEventFlagsSet(SYS_EVENTHandle, SYS_STATE_IDLE);
  /* USER CODE END RTOS_EVENTS */

}

/* USER CODE BEGIN Header_task_init */
/**
  * @brief  Function implementing the TASK_INIT thread.
  * @param  argument: Not used
  * @retval None
  */
/* USER CODE END Header_task_init */
void task_init(void *argument)
{
  /* USER CODE BEGIN task_init */
  /* Infinite loop */

  for(;;)
  {
    
    init(NULL);

  }
  /* USER CODE END task_init */
}

/* USER CODE BEGIN Header_task_key */
/**
* @brief Function implementing the TASK_KEY thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_task_key */
void task_key(void *argument)
{
  /* USER CODE BEGIN task_key */
  /* Infinite loop */
  for(;;)
  {
    key(NULL);
  }
  /* USER CODE END task_key */
}

/* USER CODE BEGIN Header_task_acquire */
/**
* @brief Function implementing the TASK_ACQUIRE thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_task_acquire */
void task_acquire(void *argument)
{
  /* USER CODE BEGIN task_acquire */
  /* Infinite loop */
  for(;;)
  {
    acquire(NULL);
  }
  /* USER CODE END task_acquire */
}

/* USER CODE BEGIN Header_task_store */
/**
* @brief Function implementing the TASK_STORE thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_task_store */
void task_store(void *argument)
{
  /* USER CODE BEGIN task_store */
  /* Infinite loop */
  for(;;)
  {
    store(NULL);
  }
  /* USER CODE END task_store */
}

/* USER CODE BEGIN Header_task_show */
/**
* @brief Function implementing the TASK_SHOW thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_task_show */
void task_show(void *argument)
{
  /* USER CODE BEGIN task_show */
  /* Infinite loop */
  for(;;)
  {
    show(NULL);
  }
  /* USER CODE END task_show */
}

/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */

/* USER CODE END Application */

